package com.group.mall.controller;

import com.group.mall.common.Result;
import com.group.mall.domain.POJO.Collect;
import com.group.mall.domain.VO.CollectVO;
import com.group.mall.domain.VO.CollectVO1;
import com.group.mall.service.CollectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

/**
 * @Author：xiexu
 * @Date：2024/6/18 14:20
 */
@RestController
@Controller
@RequestMapping("/collect")
@Slf4j
public class CollectController {
    @Autowired
    CollectService collectService;

    @GetMapping("/list/{userId}")
    public List<CollectVO> getCollectList(@PathVariable("userId") Integer userId) {
        List<CollectVO> collectList = collectService.getCollectList(userId);
        System.out.println(collectList);
        return collectList;
    }
    @PostMapping("/add")
    public Result addCollect(Collect collect) {
        collect.setCollectTime(LocalDate.now());

        if (collectService.addCollect(collect)) {
            return Result.success("收藏成功！");
        } else {
            return Result.error("收藏失败！");
        }
    }

//    @DeleteMapping("/delete")
//    public Result deleteCollect(CollectVO1 collectVO1) {
//        Integer userId = collectVO1.getUserId();
//        Integer goodId = collectVO1.getGoodId();
//        System.out.println(userId + " " + goodId);
//        if (collectService.deleteCollect(userId, goodId)) {
//            return Result.success("取消收藏成功！");
//        } else {
//            return Result.error("取消收藏失败！");
//        }
//    }
        @GetMapping("/delete/{userId}/{goodId}")
        public Result deleteCollect(@PathVariable("userId") Integer userId, @PathVariable("goodId") Integer goodId) {
            log.info("deleteCollect userId:{}, goodId:{}", userId, goodId);
            if (collectService.deleteCollect(userId, goodId)) {
                return Result.success("取消收藏成功！");
            } else {
                return Result.error("取消收藏失败！");
            }
        }
}
